﻿using SMDB_Connect.SMDB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.SessionState;

namespace GS_OM.SMHandler
{
    /// <summary>
    /// SubmitProduct 的摘要说明
    /// </summary>
    public class SubmitProduct : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            DBOPush Push = new DBOPush
            {
                Push_Prod_ID = context.Request.Form[8],
                Push_Name = context.Request.Form[0],
                Push_Msg = context.Request.Form[1],
                Push_Type = context.Request.Form[2],
                Push_Approval = context.Request.Form[4],
                Push_Active = context.Request.Form[5],
                Push_Pub_Date = DateTime.Now,
                Push_Start = DateTime.Now,
                Push_End = DateTime.Now,
                Acc_ID = Convert.ToInt32(context.Session["SID"]),
                Push_ID = Convert.ToInt32(context.Request.Form[7] == "" ? "0" : context.Request.Form[7]),
            };
            SMDB_Mgr Mgr = new SMDB_Mgr();
            string[] ProductImg = context.Request.Form[3].Split('-');
            int PushID = context.Request.Form[6] != "updatePro" ? Mgr.PushNew(Push) : Mgr.PushEdit(Push);
            for (int i = 0; i < ProductImg.Length; i++)
            {
                if (ProductImg[i] != "")
                    Mgr.UploadRes(PushID, ProductImg[i]);
            }
            context.Response.Write(PushID > 0 ? "true" : "false");
            context.Response.End();

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}